package com.sf.dlb.controller;


import com.sf.dlb.bean.UserShieldBean;
import com.sf.dlb.constant.ResponseConstant;
import com.sf.dlb.jpa.model.TokenEntity;
import com.sf.dlb.service.UserShieldService;
import com.sf.dlb.utils.GsonUtils;
import com.sf.dlb.utils.ResultVOUtil;
import com.sf.dlb.vo.ResultVO;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;


/**
 * 屏蔽
 * Created by jing.tan on 2018/12/10.
 */
@RestController
@RequestMapping(value = "/v1/shield")
public class UserShieldController {
    private static Logger logger = LoggerFactory.getLogger(UserShieldController.class);
    @Autowired
    private UserShieldService userShieldService;

    /**
     * 添加屏蔽
     * @returns
     */
    @PostMapping(value = "/add")
    @ResponseBody
    public Object addShield(HttpServletRequest request,@RequestBody UserShieldBean userShieldBean) {
        logger.info("addShield start ");
        ResultVO resultVO=(ResultVO)request.getAttribute("token");
        if(StringUtils.isBlank(userShieldBean.getShieldType())){
            userShieldBean.setShieldType("1");//默认屏蔽的是新闻
        }
        if(StringUtils.isBlank(userShieldBean.getShieldId())){
            return ResultVOUtil.error(ResponseConstant.ERROR,"屏蔽Id不能为空");
        }
        TokenEntity tokenEntity=(TokenEntity)resultVO.getData();
        userShieldBean.setUserId(tokenEntity.getUserId());
        resultVO= userShieldService.addShield(userShieldBean);
        logger.info("addShield response json === " + GsonUtils.getInstance().toJson(resultVO));
        return resultVO;
    }
}
